home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: jlilley@ix.netcom.com (John Lilley)
- Newsgroups: comp.lang.c++
- Subject: Re: delete or delete [] ?
- Date: 3 Apr 1996 14:46:40 GMT
- Organization: Netcom
- Message-ID: <4ju30g$96q@cloner2.ix.netcom.com>
- References: <4jpe5j$3vo@doc.zippo.com>
- NNTP-Posting-Host: den-co11-06.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-NETCOM-Date: Wed Apr 03 6:46:40 AM PST 1996
- X-Newsreader: WinVN 0.99.7
-
- >Actually it is quite simple, if the object is not an array, use delete; if it
- >is an array use delete [].
- >
- >You example works, and so will any example, is because of the way deallocating
- >a memory location occupy by an object and an array is just the same. The difference
- >between delete and delete[] is that delete [] will call the destructor for each
- >item in the array. Because int doesn't have a destructor, so it doesn't matter
- >if you use delete or delete[].
- >Clarence Chiang
-
- Please be careful giving advice on this! The operators delete and delete[] need not
- be implemented identically, especially since in the ANSI draft (and I believe the
- ARM?) one can override one operator pair (new/delete or new[]/delete[]) without the
- overriding the other. In addition, some implementations of new[]/delete[] allocate
- data preceding the returned memory pointer to keep track of the number and size of
- the objects in the array.
-
- The rule is: if you allocate with new[], then free with delete[].
- In your example, I believe that operator new[] is called for allocation,
- since the type is an array, so call operator delete[] to free it.
-
- john lilley
-
-
-
-